{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 高德地图API "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 地理编码 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests\n",
    "key = '7f3d4ed0570b71e0d28f4563d360714a'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "def geo(address,city=None,batch=None,sig=None)->dict:\n",
    "    \"\"\"获取地理编码\"\"\"\n",
    "    url = 'https://restapi.amap.com/v3/geocode/geo?parameters'\n",
    "    params={\n",
    "        'key':key,\n",
    "        'address':address,\n",
    "        'city':city,\n",
    "        'batch':batch,\n",
    "        'sig':sig,\n",
    "        'output':'json'\n",
    "    }\n",
    "    response = requests.get(url,params=params)\n",
    "    data = response.json()['geocodes'][0]['location'] ###提取经纬\n",
    "    return data\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'113.679287,23.632575'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "geo('广东省广州市从化区中山大学南方学院','广州')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'113.632401,23.616941'"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "geo('广东省广州市从化区温泉镇政府','广州')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 逆地理编码"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "def regeo(location,poitype=None,radius=None,extensions=\"base\",batch=False,roadlevel=None,sig=None,homeorcorp=None)->dict:\n",
    "    \"\"\"获取逆地理编码\"\"\"\n",
    "    url = 'https://restapi.amap.com/v3/geocode/regeo?parameters'\n",
    "    params={\n",
    "        'key':key,\n",
    "        'location':location,\n",
    "        'poitype':poitype,\n",
    "        'radius':radius,\n",
    "        'extensions':extensions,\n",
    "        'batch':batch,\n",
    "        'roadlevel':roadlevel,\n",
    "        'homeorcorp':homeorcorp,\n",
    "        'sig':sig,\n",
    "        'output':'json'\n",
    "    }\n",
    "    response = requests.get(url,params=params)\n",
    "    data = response.json()\n",
    "    return data\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'status': '1',\n",
       " 'regeocode': {'addressComponent': {'city': '广州市',\n",
       "   'province': '广东省',\n",
       "   'adcode': '440117',\n",
       "   'district': '从化区',\n",
       "   'towncode': '440117103000',\n",
       "   'streetNumber': {'number': '7号',\n",
       "    'location': '113.6786,23.6333289',\n",
       "    'direction': '西北',\n",
       "    'distance': '109.203',\n",
       "    'street': '博学路'},\n",
       "   'country': '中国',\n",
       "   'township': '温泉镇',\n",
       "   'businessAreas': [[]],\n",
       "   'building': {'name': [], 'type': []},\n",
       "   'neighborhood': {'name': [], 'type': []},\n",
       "   'citycode': '020'},\n",
       "  'formatted_address': '广东省广州市从化区温泉镇中山大学南方学院'},\n",
       " 'info': 'OK',\n",
       " 'infocode': '10000'}"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "regeo('113.679287,23.632575')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 路径规划 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "def walking(origin:str,destination:str,)->dict:\n",
    "    url = 'https://restapi.amap.com/v3/direction/walking?parameters'\n",
    "    params={\n",
    "        'key':key,\n",
    "        'origin':origin,\n",
    "        'destination':destination,\n",
    "        'output':'json'\n",
    "    }\n",
    "    response = requests.get(url,params=params)\n",
    "    data = response.json()['route']['paths'][0]['steps']\n",
    "    for i in range(0,len(data)):\n",
    "        print(data[int(i)]['instruction'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "向南步行161米右转\n",
      "向西步行99米左转\n",
      "向南步行237米左转\n",
      "向南步行498米向右前方行走\n",
      "沿源富街向西南步行1568米直行\n",
      "沿源湖街向西步行784米右转\n",
      "沿龙泉路向西北步行1723米向左前方行走\n",
      "沿龙泉路向西步行67米向左前方行走\n",
      "沿温泉大道向西步行22米右转\n",
      "步行13米左转\n",
      "沿温泉大道向西南步行1425米右转\n",
      "向西北步行96米右转\n",
      "向北步行66米到达目的地\n"
     ]
    }
   ],
   "source": [
    "walking(geo(\"广东省广州市中山大学南方学院\",\"广州\"),geo(\"广东省广州市从化区温泉镇政府\",\"广州\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 行政区域查询"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "def district(keywords:str)->dict:\n",
    "    url='https://restapi.amap.com/v3/config/district?parameters'\n",
    "    params={\n",
    "        'key':key,\n",
    "        'keywords':keywords,\n",
    "        'output':'json'\n",
    "    }\n",
    "\n",
    "    r = requests.get(url,params=params)\n",
    "    data = r.json()['districts'][0]['districts']\n",
    "    print(\"----\"+keywords+ \"有以下----\")\n",
    "    for i in data:\n",
    "        print(i['name'])\n",
    "    return "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "----广东有以下----\n",
      "肇庆市\n",
      "佛山市\n",
      "汕头市\n",
      "惠州市\n",
      "深圳市\n",
      "珠海市\n",
      "湛江市\n",
      "阳江市\n",
      "汕尾市\n",
      "潮州市\n",
      "江门市\n",
      "云浮市\n",
      "东沙群岛\n",
      "茂名市\n",
      "河源市\n",
      "梅州市\n",
      "东莞市\n",
      "揭阳市\n",
      "清远市\n",
      "韶关市\n",
      "广州市\n",
      "中山市\n"
     ]
    }
   ],
   "source": [
    "district('广东')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 搜索POI"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "用到推荐算法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'status': '1',\n",
       " 'count': '82',\n",
       " 'info': 'OK',\n",
       " 'infocode': '10000',\n",
       " 'suggestion': {'keywords': [], 'cities': []},\n",
       " 'pois': [{'id': 'B0FFK712FX',\n",
       "   'parent': 'B0FFF5RJ1U',\n",
       "   'childtype': '202',\n",
       "   'name': '喜茶(凯华国际DP店)',\n",
       "   'type': '餐饮服务;冷饮店;冷饮店',\n",
       "   'typecode': '050700',\n",
       "   'biz_type': 'diner',\n",
       "   'address': '冼村路5号104房近K11凯华国际中心',\n",
       "   'location': '113.327219,23.117334',\n",
       "   'tel': '020-85208628',\n",
       "   'distance': [],\n",
       "   'biz_ext': [],\n",
       "   'pname': '广东省',\n",
       "   'cityname': '广州市',\n",
       "   'adname': '天河区',\n",
       "   'importance': [],\n",
       "   'shopid': [],\n",
       "   'shopinfo': '0',\n",
       "   'poiweight': [],\n",
       "   'photos': []},\n",
       "  {'id': 'B0FFK7127Y',\n",
       "   'parent': 'B02F38PFKU',\n",
       "   'childtype': '202',\n",
       "   'name': '喜茶(蛇口网谷GO店)',\n",
       "   'type': '餐饮服务;冷饮店;冷饮店',\n",
       "   'typecode': '050700',\n",
       "   'biz_type': 'diner',\n",
       "   'address': '南海大道1057号科技大厦2期B栋103房',\n",
       "   'location': '113.918523,22.494681',\n",
       "   'tel': '0755-26673095',\n",
       "   'distance': [],\n",
       "   'biz_ext': [],\n",
       "   'pname': '广东省',\n",
       "   'cityname': '深圳市',\n",
       "   'adname': '南山区',\n",
       "   'importance': [],\n",
       "   'shopid': [],\n",
       "   'shopinfo': '0',\n",
       "   'poiweight': [],\n",
       "   'photos': []},\n",
       "  {'id': 'B0FFK7122K',\n",
       "   'parent': [],\n",
       "   'childtype': [],\n",
       "   'name': '喜茶(园岭星光广场GO店)',\n",
       "   'type': '餐饮服务;冷饮店;冷饮店',\n",
       "   'typecode': '050700',\n",
       "   'biz_type': 'diner',\n",
       "   'address': '红岭中路2061号园岭花园裙楼1楼1010号铺',\n",
       "   'location': '114.104188,22.555112',\n",
       "   'tel': '0755-25129404',\n",
       "   'distance': [],\n",
       "   'biz_ext': [],\n",
       "   'pname': '广东省',\n",
       "   'cityname': '深圳市',\n",
       "   'adname': '福田区',\n",
       "   'importance': [],\n",
       "   'shopid': [],\n",
       "   'shopinfo': '0',\n",
       "   'poiweight': [],\n",
       "   'photos': []},\n",
       "  {'id': 'B0FFK711WJ',\n",
       "   'parent': 'B0FFGDDLUB',\n",
       "   'childtype': '202',\n",
       "   'name': '喜茶(盈峰中心GO店)',\n",
       "   'type': '餐饮服务;冷饮店;冷饮店',\n",
       "   'typecode': '050700',\n",
       "   'biz_type': 'diner',\n",
       "   'address': '盈峰中心1层108室',\n",
       "   'location': '113.939499,22.522579',\n",
       "   'tel': '0755-26904965',\n",
       "   'distance': [],\n",
       "   'biz_ext': [],\n",
       "   'pname': '广东省',\n",
       "   'cityname': '深圳市',\n",
       "   'adname': '南山区',\n",
       "   'importance': [],\n",
       "   'shopid': [],\n",
       "   'shopinfo': '0',\n",
       "   'poiweight': [],\n",
       "   'photos': []},\n",
       "  {'id': 'B0FFK711S0',\n",
       "   'parent': [],\n",
       "   'childtype': [],\n",
       "   'name': '喜茶(丰盛町GO店)',\n",
       "   'type': '餐饮服务;冷饮店;冷饮店',\n",
       "   'typecode': '050700',\n",
       "   'biz_type': 'diner',\n",
       "   'address': '车公庙丰盛町地下阳光街BCD区C1-089,C1-091,C1-093B',\n",
       "   'location': '114.024776,22.535568',\n",
       "   'tel': '0755-82544156;13510507476',\n",
       "   'distance': [],\n",
       "   'biz_ext': [],\n",
       "   'pname': '广东省',\n",
       "   'cityname': '深圳市',\n",
       "   'adname': '福田区',\n",
       "   'importance': [],\n",
       "   'shopid': [],\n",
       "   'shopinfo': '0',\n",
       "   'poiweight': [],\n",
       "   'photos': []},\n",
       "  {'id': 'B0FFK711LW',\n",
       "   'parent': [],\n",
       "   'childtype': [],\n",
       "   'name': '喜茶(中科纳能GO店)',\n",
       "   'type': '餐饮服务;冷饮店;冷饮店',\n",
       "   'typecode': '050700',\n",
       "   'biz_type': 'diner',\n",
       "   'address': '粤兴六道中科纳能大厦B座1层B02',\n",
       "   'location': '113.941148,22.526739',\n",
       "   'tel': '0755-33315903',\n",
       "   'distance': [],\n",
       "   'biz_ext': [],\n",
       "   'pname': '广东省',\n",
       "   'cityname': '深圳市',\n",
       "   'adname': '南山区',\n",
       "   'importance': [],\n",
       "   'shopid': [],\n",
       "   'shopinfo': '0',\n",
       "   'poiweight': [],\n",
       "   'photos': []},\n",
       "  {'id': 'B0FFK711G1',\n",
       "   'parent': 'B02F300988',\n",
       "   'childtype': '202',\n",
       "   'name': '喜茶(紫荆城GO店)',\n",
       "   'type': '餐饮服务;冷饮店;冷饮店|购物服务;购物相关场所;购物相关场所',\n",
       "   'typecode': '050700|060000',\n",
       "   'biz_type': 'diner',\n",
       "   'address': '振兴路55号紫荆城商业广场1层A16号',\n",
       "   'location': '114.088713,22.546379',\n",
       "   'tel': '0755-83258250',\n",
       "   'distance': [],\n",
       "   'biz_ext': [],\n",
       "   'pname': '广东省',\n",
       "   'cityname': '深圳市',\n",
       "   'adname': '福田区',\n",
       "   'importance': [],\n",
       "   'shopid': [],\n",
       "   'shopinfo': '0',\n",
       "   'poiweight': [],\n",
       "   'photos': []},\n",
       "  {'id': 'B0FFK7117H',\n",
       "   'parent': [],\n",
       "   'childtype': [],\n",
       "   'name': '喜茶(海上世界店)',\n",
       "   'type': '餐饮服务;冷饮店;冷饮店',\n",
       "   'typecode': '050700',\n",
       "   'biz_type': 'diner',\n",
       "   'address': '海滨花园商业中心1栋103铺海上世界A出口KFC旁',\n",
       "   'location': '113.915632,22.484082',\n",
       "   'tel': '0755-21614591',\n",
       "   'distance': [],\n",
       "   'biz_ext': [],\n",
       "   'pname': '广东省',\n",
       "   'cityname': '深圳市',\n",
       "   'adname': '南山区',\n",
       "   'importance': [],\n",
       "   'shopid': [],\n",
       "   'shopinfo': '0',\n",
       "   'poiweight': [],\n",
       "   'photos': []},\n",
       "  {'id': 'B0FFK71106',\n",
       "   'parent': 'B0FFFZRC7K',\n",
       "   'childtype': '201',\n",
       "   'name': '喜茶(深圳机场GO店)',\n",
       "   'type': '餐饮服务;冷饮店;冷饮店',\n",
       "   'typecode': '050700',\n",
       "   'biz_type': 'diner',\n",
       "   'address': '宝安国际机场航站楼3S-08-01近23号登机口',\n",
       "   'location': '113.811463,22.628429',\n",
       "   'tel': '0755-26659705',\n",
       "   'distance': [],\n",
       "   'biz_ext': [],\n",
       "   'pname': '广东省',\n",
       "   'cityname': '深圳市',\n",
       "   'adname': '宝安区',\n",
       "   'importance': [],\n",
       "   'shopid': [],\n",
       "   'shopinfo': '0',\n",
       "   'poiweight': [],\n",
       "   'photos': []},\n",
       "  {'id': 'B0FFK710VQ',\n",
       "   'parent': 'B0FFJ6C1YS',\n",
       "   'childtype': '202',\n",
       "   'name': '喜茶(深圳湾GO店)',\n",
       "   'type': '餐饮服务;冷饮店;冷饮店',\n",
       "   'typecode': '050700',\n",
       "   'biz_type': 'diner',\n",
       "   'address': '高新南九道10号深圳湾科技生态园3区10栋裙楼01层33-34号',\n",
       "   'location': '113.951604,22.530259',\n",
       "   'tel': '0755-86966251',\n",
       "   'distance': [],\n",
       "   'biz_ext': [],\n",
       "   'pname': '广东省',\n",
       "   'cityname': '深圳市',\n",
       "   'adname': '南山区',\n",
       "   'importance': [],\n",
       "   'shopid': [],\n",
       "   'shopinfo': '0',\n",
       "   'poiweight': [],\n",
       "   'photos': []},\n",
       "  {'id': 'B0FFJFTOC0',\n",
       "   'parent': 'B0FFG23ZZ1',\n",
       "   'childtype': '201',\n",
       "   'name': '喜茶(IGC天汇广场)',\n",
       "   'type': '餐饮服务;冷饮店;冷饮店',\n",
       "   'typecode': '050700',\n",
       "   'biz_type': 'diner',\n",
       "   'address': '珠江新城兴民路222号IGC天汇广场B1层B115',\n",
       "   'location': '113.332961,23.116459',\n",
       "   'tel': '020-37392323',\n",
       "   'distance': [],\n",
       "   'biz_ext': [],\n",
       "   'pname': '广东省',\n",
       "   'cityname': '广州市',\n",
       "   'adname': '天河区',\n",
       "   'importance': [],\n",
       "   'shopid': [],\n",
       "   'shopinfo': '0',\n",
       "   'poiweight': [],\n",
       "   'photos': []},\n",
       "  {'id': 'B0FFJCSNWN',\n",
       "   'parent': 'B0FFH0YOUV',\n",
       "   'childtype': '202',\n",
       "   'name': '喜茶(讯美科技GO店)',\n",
       "   'type': '餐饮服务;餐饮相关场所;餐饮相关',\n",
       "   'typecode': '050000',\n",
       "   'biz_type': 'diner',\n",
       "   'address': '粤海街道科苑路8号讯美科技广场3号楼大堂部分区域',\n",
       "   'location': '113.945711,22.545916',\n",
       "   'tel': '0755-26929157',\n",
       "   'distance': [],\n",
       "   'biz_ext': [],\n",
       "   'pname': '广东省',\n",
       "   'cityname': '深圳市',\n",
       "   'adname': '南山区',\n",
       "   'importance': [],\n",
       "   'shopid': [],\n",
       "   'shopinfo': '0',\n",
       "   'poiweight': [],\n",
       "   'photos': []},\n",
       "  {'id': 'B0FFJ8YP49',\n",
       "   'parent': 'B0FFH11N97',\n",
       "   'childtype': '201',\n",
       "   'name': '喜茶(富力海珠城热麦店)',\n",
       "   'type': '餐饮服务;冷饮店;冷饮店',\n",
       "   'typecode': '050700',\n",
       "   'biz_type': 'diner',\n",
       "   'address': '江南西路1号富力海珠城A区1楼101B',\n",
       "   'location': '113.273143,23.095547',\n",
       "   'tel': '020-85208698',\n",
       "   'distance': [],\n",
       "   'biz_ext': [],\n",
       "   'pname': '广东省',\n",
       "   'cityname': '广州市',\n",
       "   'adname': '海珠区',\n",
       "   'importance': [],\n",
       "   'shopid': [],\n",
       "   'shopinfo': '0',\n",
       "   'poiweight': [],\n",
       "   'photos': []},\n",
       "  {'id': 'B0FFJ7UKHX',\n",
       "   'parent': [],\n",
       "   'childtype': [],\n",
       "   'name': 'HEYTEA(讯美科技店)',\n",
       "   'type': '餐饮服务;餐饮相关场所;餐饮相关',\n",
       "   'typecode': '050000',\n",
       "   'biz_type': 'diner',\n",
       "   'address': [],\n",
       "   'location': '113.945786,22.545666',\n",
       "   'tel': [],\n",
       "   'distance': [],\n",
       "   'biz_ext': [],\n",
       "   'pname': '广东省',\n",
       "   'cityname': '深圳市',\n",
       "   'adname': '南山区',\n",
       "   'importance': [],\n",
       "   'shopid': [],\n",
       "   'shopinfo': '0',\n",
       "   'poiweight': [],\n",
       "   'photos': []},\n",
       "  {'id': 'B0FFJ4QTCW',\n",
       "   'parent': 'B0FFHEJYQ3',\n",
       "   'childtype': '201',\n",
       "   'name': '喜茶(海雅缤纷广场南山店)',\n",
       "   'type': '餐饮服务;冷饮店;冷饮店',\n",
       "   'typecode': '050700',\n",
       "   'biz_type': 'diner',\n",
       "   'address': '南海大道海雅缤纷城广场1楼1S49号',\n",
       "   'location': '113.929479,22.518569',\n",
       "   'tel': '0755-26914953',\n",
       "   'distance': [],\n",
       "   'biz_ext': [],\n",
       "   'pname': '广东省',\n",
       "   'cityname': '深圳市',\n",
       "   'adname': '南山区',\n",
       "   'importance': [],\n",
       "   'shopid': [],\n",
       "   'shopinfo': '0',\n",
       "   'poiweight': [],\n",
       "   'photos': []},\n",
       "  {'id': 'B0FFJ2K8GS',\n",
       "   'parent': 'B0FFF05SW2',\n",
       "   'childtype': '202',\n",
       "   'name': '喜茶(小榄海港城店)',\n",
       "   'type': '餐饮服务;冷饮店;冷饮店',\n",
       "   'typecode': '050700',\n",
       "   'biz_type': 'diner',\n",
       "   'address': '小榄镇升平东路1号海港城1层',\n",
       "   'location': '113.256635,22.673452',\n",
       "   'tel': '0760-22113800',\n",
       "   'distance': [],\n",
       "   'biz_ext': [],\n",
       "   'pname': '广东省',\n",
       "   'cityname': '中山市',\n",
       "   'adname': '中山市',\n",
       "   'importance': [],\n",
       "   'shopid': [],\n",
       "   'shopinfo': '0',\n",
       "   'poiweight': [],\n",
       "   'photos': []},\n",
       "  {'id': 'B0FFJ1M4JL',\n",
       "   'parent': 'B02F37UI67',\n",
       "   'childtype': '302',\n",
       "   'name': 'HEYTEA喜茶(龙城万科里)',\n",
       "   'type': '餐饮服务;冷饮店;冷饮店',\n",
       "   'typecode': '050700',\n",
       "   'biz_type': 'diner',\n",
       "   'address': '中心城龙翔大道龙城万科里L1层49号',\n",
       "   'location': '114.251029,22.716860',\n",
       "   'tel': '0755-28909053',\n",
       "   'distance': [],\n",
       "   'biz_ext': [],\n",
       "   'pname': '广东省',\n",
       "   'cityname': '深圳市',\n",
       "   'adname': '龙岗区',\n",
       "   'importance': [],\n",
       "   'shopid': [],\n",
       "   'shopinfo': '0',\n",
       "   'poiweight': [],\n",
       "   'photos': []},\n",
       "  {'id': 'B0FFIZD8TX',\n",
       "   'parent': 'B0FFJ16G8Q',\n",
       "   'childtype': '202',\n",
       "   'name': '喜茶(布吉万象汇店)',\n",
       "   'type': '餐饮服务;餐饮相关场所;餐饮相关',\n",
       "   'typecode': '050000',\n",
       "   'biz_type': 'diner',\n",
       "   'address': '布吉街道翔鸽路2号布吉万象汇L1层L177号',\n",
       "   'location': '114.131178,22.592368',\n",
       "   'tel': '0755-28918620',\n",
       "   'distance': [],\n",
       "   'biz_ext': [],\n",
       "   'pname': '广东省',\n",
       "   'cityname': '深圳市',\n",
       "   'adname': '龙岗区',\n",
       "   'importance': [],\n",
       "   'shopid': [],\n",
       "   'shopinfo': '0',\n",
       "   'poiweight': [],\n",
       "   'photos': []},\n",
       "  {'id': 'B0FFIZ46UQ',\n",
       "   'parent': [],\n",
       "   'childtype': [],\n",
       "   'name': '喜茶(利和新地店)',\n",
       "   'type': '餐饮服务;冷饮店;冷饮店',\n",
       "   'typecode': '050700',\n",
       "   'biz_type': 'diner',\n",
       "   'address': '银通街2号利和公寓利和新地汇首层20卡之2',\n",
       "   'location': '113.385060,22.511468',\n",
       "   'tel': '0760-88325552',\n",
       "   'distance': [],\n",
       "   'biz_ext': [],\n",
       "   'pname': '广东省',\n",
       "   'cityname': '中山市',\n",
       "   'adname': '中山市',\n",
       "   'importance': [],\n",
       "   'shopid': [],\n",
       "   'shopinfo': '0',\n",
       "   'poiweight': [],\n",
       "   'photos': []},\n",
       "  {'id': 'B0FFIVFGNL',\n",
       "   'parent': 'B0FFJ939YR',\n",
       "   'childtype': '201',\n",
       "   'name': '喜茶(天环广场东塔)',\n",
       "   'type': '餐饮服务;冷饮店;冷饮店',\n",
       "   'typecode': '050700',\n",
       "   'biz_type': 'diner',\n",
       "   'address': '天河路218号天环广场东塔B2层B234-35',\n",
       "   'location': '113.324995,23.132926',\n",
       "   'tel': '020-85201328',\n",
       "   'distance': [],\n",
       "   'biz_ext': [],\n",
       "   'pname': '广东省',\n",
       "   'cityname': '广州市',\n",
       "   'adname': '天河区',\n",
       "   'importance': [],\n",
       "   'shopid': [],\n",
       "   'shopinfo': '0',\n",
       "   'poiweight': [],\n",
       "   'photos': []}]}"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import requests\n",
    "key = '7f3d4ed0570b71e0d28f4563d360714a'\n",
    "def place_text(keywords,city=None,citylimit=None,children=None,page=None,extensions='base',sig=None)->dict:\n",
    "    url = 'https://restapi.amap.com/v3/place/text?parameters'\n",
    "    params={\n",
    "        'key':key,\n",
    "        'keywords':keywords,\n",
    "        'city':city,\n",
    "        'citylimit':citylimit,\n",
    "        'children':children,\n",
    "        'page':page,\n",
    "        'extensions':extensions,\n",
    "        'output':'json'\n",
    "    }\n",
    "    r = requests.get(url,params=params)\n",
    "    \n",
    "    data = r.json()\n",
    "    return data\n",
    "喜茶 = place_text('喜茶',city=\"广东\")\n",
    "喜茶\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "name\n"
     ]
    }
   ],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### IP定位 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests\n",
    "key = '7f3d4ed0570b71e0d28f4563d360714a'\n",
    "def ip(ip:str):\n",
    "    parameters = {\n",
    "    'key':key,\n",
    "    'ip':ip,\n",
    "     'output':'json'\n",
    "    }\n",
    "    r = requests.get(\"https://restapi.amap.com/v3/ip?parameters\",params=parameters)\n",
    "    data = r.json()\n",
    "    del data['status']\n",
    "    del data['info']\n",
    "    df = [\"省份: %s\"%(data['province']),\"地区: %s\"%(data['city']),\"地理编码: %s\"%(data['adcode']),\"经纬度: %s\"%(data['rectangle'])]\n",
    "    print(\"ip:\"+ip)\n",
    "    for i in df:\n",
    "          print(i)\n",
    "    return\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "ip:120.239.9.243\n",
      "省份: 广东省\n",
      "地区: 汕头市\n",
      "地理编码: 440500\n",
      "经纬度: 116.6117942,23.28637076;116.8215644,23.45797106\n"
     ]
    }
   ],
   "source": [
    "ip('120.239.9.243')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 静态地图"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "计算机视觉"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'113.679287,23.632575'"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "### 获取编码\n",
    "def geo(address,city=None,batch=None,sig=None)->dict:\n",
    "    \"\"\"获取地理编码\"\"\"\n",
    "    url = 'https://restapi.amap.com/v3/geocode/geo?parameters'\n",
    "    params={\n",
    "        'key':key,\n",
    "        'address':address,\n",
    "        'city':city,\n",
    "        'batch':batch,\n",
    "        'sig':sig,\n",
    "        'output':'json'\n",
    "    }\n",
    "    response = requests.get(url,params=params)\n",
    "    data = response.json()['geocodes'][0]['location'] ###提取经纬\n",
    "    return data\n",
    "geo('广东省广州市从化区中山大学南方学院','广州')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "def map(location:str,zoom:str):\n",
    "    parameters = {\n",
    "       'key':key,\n",
    "       'location':location,\n",
    "       'zoom':zoom,\n",
    "        \n",
    "    }\n",
    "    r = requests.get(\"https://restapi.amap.com/v3/staticmap?parameters\",params=parameters)\n",
    "    data = r.url\n",
    "    return data\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'https://restapi.amap.com/v3/staticmap?parameters&key=7f3d4ed0570b71e0d28f4563d360714a&location=113.679287%2C23.632575&zoom=18'"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "map(geo('广东省广州市从化区中山大学南方学院','广州'),18)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 坐标转换 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "def assisant(locations:str,coordsys:str):\n",
    "    parameters = {\n",
    "        'key':key,\n",
    "        'locations':locations,\n",
    "        'coordsys':coordsys,\n",
    "        'output':'json'\n",
    "    }\n",
    "    r = requests.get(\"https://restapi.amap.com/v3/assistant/coordinate/convert?parameters\",params=parameters)\n",
    "    data = r.json()['locations']\n",
    "    return data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'116.487585177952,39.991754014757;116.487585177952,39.991626519098'"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "assisant(\"116.481499,39.990475|116.481499,39.9903475\",'gps')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 天气查询 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "def weather(city:str):\n",
    "    parameters = {\n",
    "        'key':key,\n",
    "        'city':city,\n",
    "        'output':'json'\n",
    "    }\n",
    "    r = requests.get(\"https://restapi.amap.com/v3/weather/weatherInfo?parameters\",params=parameters)\n",
    "    data = r.json()\n",
    "    return data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'status': '1',\n",
       " 'count': '1',\n",
       " 'info': 'OK',\n",
       " 'infocode': '10000',\n",
       " 'lives': [{'province': '广东',\n",
       "   'city': '汕头市',\n",
       "   'adcode': '440500',\n",
       "   'weather': '多云',\n",
       "   'temperature': '26',\n",
       "   'winddirection': '东南',\n",
       "   'windpower': '≤3',\n",
       "   'humidity': '73',\n",
       "   'reporttime': '2020-04-20 14:22:34'}]}"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "weather('汕头')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 输入提示 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "def inputtips(keywords:str):\n",
    "    parameters = {\n",
    "        'key':key,\n",
    "        'keywords':keywords,\n",
    "        'output':'json'\n",
    "    }\n",
    "    r = requests.get(\"https://restapi.amap.com/v3/assistant/inputtips?parameters\",params=parameters)\n",
    "    data = r.json()\n",
    "    return data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'status': '1',\n",
       " 'count': '10',\n",
       " 'info': 'OK',\n",
       " 'infocode': '10000',\n",
       " 'tips': [{'id': 'B000A7BD6C',\n",
       "   'name': '清华大学',\n",
       "   'district': '北京市海淀区',\n",
       "   'adcode': '110108',\n",
       "   'location': '116.326836,40.00366',\n",
       "   'address': '双清路30号',\n",
       "   'typecode': '141201',\n",
       "   'city': []},\n",
       "  {'id': 'B000A7GRM1',\n",
       "   'name': '清华大学(南门)',\n",
       "   'district': '北京市海淀区',\n",
       "   'adcode': '110108',\n",
       "   'location': '116.328806,39.994705',\n",
       "   'address': '学堂路',\n",
       "   'typecode': '991400',\n",
       "   'city': []},\n",
       "  {'id': 'B000A87L0Q',\n",
       "   'name': '清华大学(西门)',\n",
       "   'district': '北京市海淀区',\n",
       "   'adcode': '110108',\n",
       "   'location': '116.315374,39.999908',\n",
       "   'address': '双清路30号清华大学',\n",
       "   'typecode': '991400',\n",
       "   'city': []},\n",
       "  {'id': 'B000A80Z29',\n",
       "   'name': '清华大学(东南门)',\n",
       "   'district': '北京市海淀区',\n",
       "   'adcode': '110108',\n",
       "   'location': '116.33283,39.996496',\n",
       "   'address': '双清路',\n",
       "   'typecode': '991400',\n",
       "   'city': []},\n",
       "  {'id': 'B000A830DB',\n",
       "   'name': '清华大学(北门)',\n",
       "   'district': '北京市海淀区',\n",
       "   'adcode': '110108',\n",
       "   'location': '116.323203,40.010386',\n",
       "   'address': '双清路30号',\n",
       "   'typecode': '991400',\n",
       "   'city': []},\n",
       "  {'id': 'B000A7IF8E',\n",
       "   'name': '清华大学(西南门)',\n",
       "   'district': '北京市海淀区',\n",
       "   'adcode': '110108',\n",
       "   'location': '116.321104,39.993444',\n",
       "   'address': '清华南路',\n",
       "   'typecode': '991400',\n",
       "   'city': []},\n",
       "  {'id': 'B000A84BAO',\n",
       "   'name': '清华大学(东北门)',\n",
       "   'district': '北京市海淀区',\n",
       "   'adcode': '110108',\n",
       "   'location': '116.33526,40.009365',\n",
       "   'address': '清华园清华大学',\n",
       "   'typecode': '991400',\n",
       "   'city': []},\n",
       "  {'id': 'B000A96G3A',\n",
       "   'name': '清华大学-二教',\n",
       "   'district': '北京市海淀区',\n",
       "   'adcode': '110108',\n",
       "   'location': '116.324019,40.002307',\n",
       "   'address': '清华路附近',\n",
       "   'typecode': '141200',\n",
       "   'city': []},\n",
       "  {'id': 'B000A8W5YF',\n",
       "   'name': '清华大学大礼堂',\n",
       "   'district': '北京市海淀区',\n",
       "   'adcode': '110108',\n",
       "   'location': '116.32441,40.003706',\n",
       "   'address': '成府路45-1号清华园1号',\n",
       "   'typecode': '140300',\n",
       "   'city': []},\n",
       "  {'id': 'B000A7IF75',\n",
       "   'name': '清华大学第一附属医院',\n",
       "   'district': '北京市朝阳区',\n",
       "   'adcode': '110105',\n",
       "   'location': '116.494524,39.965551',\n",
       "   'address': '酒仙桥一街坊6号',\n",
       "   'typecode': '090100',\n",
       "   'city': []}]}"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "inputtips(\"清华大学\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 交通态势 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "def rectangle(rectangle:str):\n",
    "    parameters = {\n",
    "        'key':key,\n",
    "        'rectangle':rectangle,\n",
    "        'output':'json'\n",
    "    }\n",
    "    r = requests.get(\"https://restapi.amap.com/v3/traffic/status/rectangle?parameters\",params=parameters)\n",
    "    data = r.json()\n",
    "    return data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'status': '1',\n",
       " 'info': 'OK',\n",
       " 'infocode': '10000',\n",
       " 'trafficinfo': {'description': '花园北路：航空航天大学附近自东向西严重拥堵，反向行驶缓慢。',\n",
       "  'evaluation': {'expedite': '88.89%',\n",
       "   'congested': '5.56%',\n",
       "   'blocked': '5.56%',\n",
       "   'unknown': '0.01%',\n",
       "   'status': '2',\n",
       "   'description': '轻度拥堵'}}}"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rectangle(\"116.351147,39.996309;116.357134,39.968727\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    " "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 简单的应用"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 旅行助手 "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 调用的高德API\n",
    "- IP定位\n",
    "- 搜索poi\n",
    "- 交通态势"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "产品描述：当游客到一个地方旅行时通过定位其ip，推送周边美食、住宿，以及到旅游景点到交通态势。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  },
  "toc": {
   "base_numbering": "1",
   "nav_menu": {},
   "number_sections": false,
   "sideBar": true,
   "skip_h1_title": true,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {
    "height": "calc(100% - 180px)",
    "left": "10px",
    "top": "150px",
    "width": "251px"
   },
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
